package com.intel.two.service.older.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.intel.two.common.older.LayuiPageVo;
import com.intel.two.mapper.older.ActivityMapper;
import com.intel.two.pojo.older.Activity;
import com.intel.two.service.older.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service("activityService")
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;


    @Override
    public LayuiPageVo<Activity> activityPageDate(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");

        PageHelper.startPage(page,limit);
        List<Activity> activities = activityMapper.selectByParams(params);


        PageInfo<Activity> activityPageInfo = new PageInfo<>(activities);
        LayuiPageVo<Activity> activityLayuiPageVo = new LayuiPageVo<>();
        activityLayuiPageVo.setCode(0);
        activityLayuiPageVo.setMsg("学生分页列表数据");
        activityLayuiPageVo.setCount(activityPageInfo.getTotal());  // 总记录数
        activityLayuiPageVo.setData(activityPageInfo.getList());  // 分页列表数据
        return activityLayuiPageVo;
    }

    @Override
    public int addActivity(Activity activity) {
        int result = activityMapper.addActivity(activity);
        return result;
    }

    @Override
    public int deleteById(Integer id) {
        int result = activityMapper.deleteById(id);
        return result;
    }

    @Override
    public int deleteAll(Map<String, Object> map) {
        String str = (String) map.get("oldman_id");
        String[] strs = str.split("-");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strs.length; i++) {
            list.add(Integer.parseInt(strs[i]));
            System.out.println(strs[i]);
        }
        return activityMapper.deleteAll(list);
    }

    @Override
    public int udateActivity(Activity activity) {
        int result = activityMapper.updateActivity(activity);
        return result;
    }
}
